<template>
	<div>
    <Breadcrumb :style="{margin: '15px 0',float: 'left'}">
      <BreadcrumbItem>首页</BreadcrumbItem>
      <BreadcrumbItem>会员中心</BreadcrumbItem>
      <BreadcrumbItem>联合会员</BreadcrumbItem>
    </Breadcrumb>
    <Content class="layer-content">
      <Form inline>
        <FormItem>
          <Input style="width: 400px" v-model="keywords" search enter-button placeholder="请输入关键字" @on-search="searchGet" @submit.native.prevent/>
        </FormItem>
        <FormItem>
					<Select style="width: 150px" placeholder="请选择联合会员" clearable @on-change="selectOption">
            <Option v-for="(item,index) in unionVipTypes" :value="item.type" :key="index">{{item.name}}</Option>
          </Select>
				</FormItem>
        <FormItem>
          <Button @click="reset">重置</Button>
        </FormItem>
      </Form>
      <Table border :columns="columns" :data="dataGrid"></Table>
      <HigPager v-model="query" :total="pageTotal" :init="Init"></HigPager>
    </Content>
  </div>  
</template>
<script scope>
export default {
  data () {
    return {
      pageTotal: 0,
      dataGrid:[],
      unionVipTypes: [{
        type: 0,
        name: '湘商会员特权'
      }],
      keywords: null,
      query: {
        pageIndex: 1,
        pageSize: 15
      },
      columns: [
        {
          title: "用户姓名",
          key: "userName",
          width: 230
        },
        {
          title: "联系电话",
          key: "unionMobile",
          width: 180
        },
        {
          title: "联合会员",
          key: "unionVipText"
        },
        {
          title: "审核状态",
          key: "vipStatus",
          width: 120,
          render: (h, params) => {
            return h("div", [
              h(
                "Tag",
                {
                  props: {
                    color: this.tagStyle(params.row.vipStatus)
                  },
                },
                params.row.vipStatusText
              ),
            ]);
          },
        },
        {
          title: "申请时间",
          key: "postTime",
          width: 150,
          render: (h, params) => {
            return h("div", this.$date(params.row.postTime,'yyyy-MM-dd HH:mm'));
          },
        },
        {
          title: "操作",
          key: "action",
          width: 120,
          render: (h, params) => {
            return h("Dropdown",{props: {transfer:true,trigger:'click'}},
              [
                h("a",[h("a","下拉菜单"),h("Icon",{props: {type: "ios-arrow-down"}})]),
                h("DropdownMenu",{slot: "list"},
                  [
                    h("DropdownItem",{nativeOn:{click:()=>{this.auth(params.row)}},props:{disabled: params.row.vipStatus !== 0}},"审核"),
                    h("DropdownItem",{nativeOn:{click:()=>{this.del(params.row)}},props:{divided:true}},"删除")
                  ]
                ),
              ]
            )
          }
        },
      ]
    }
  },
  components: {
    
  },
  methods: {
    auth(e) {
      if(e.vipStatus !== 0) {
        return false
      }
      this.$Modal.confirm({
        title:'温馨提示',
        content: '确定审核通过',
        onOk: () => {
          this.doAuth(e.unionVipId)
        }
      })
    },
    doAuth(unionVipId) {
      new this.$rest({
        gateway: 'agrobiz',
        service: "agrobiz-uc",
        url: "/v1.0/user-src/audit/union/vip",
        data: {
          pojo: {
            unionVipId: unionVipId,
            vipStatus: 1
          }
        },
        action: (res) => {
          if (res.data.code === 20000) {
            this.Init()
            this.$Message.success('审核成功')
          } else {
            this.$Notice.warning({
              desc: `失败原因：${res.data.msg}`,
            });
          }
        },
      }).post()
    },
    del(e) {
      this.$Modal.confirm({
        title:'温馨提示',
        content: `确定删除${e.userName}`,
        onOk: () => {
          this.doDel(e.unionVipId)
        }
      })
    },
    doDel(unionVipId) {
      new this.$rest({
        gateway: 'agrobiz',
        service: "agrobiz-uc",
        url: "/v1.0/union/vip",
        data: {
          pojo: [unionVipId]
        },
        action: (res) => {
          if (res.data.code === 20000) {
            this.Init()
            this.$Message.success('删除成功')
          } else {
            this.$Notice.warning({
              desc: `失败原因：${res.data.msg}`,
            });
          }
        },
      }).delete()
    },
    //获取列表
    Init(){
      new this.$rest({
        gateway: 'agrobiz',
        service: 'agrobiz-uc',
        url: '/v1.0/view/union/vip/page',
        query: this.query,
        action: (res) => {
          if (res.data.code === 20000) {
            this.pageTotal = res.data.data.count
            this.dataGrid = res.data.data.list
            for(let item of this.dataGrid) {
              item.vipStatusText = this.vipStatusEnum(item.vipStatus)
              item.unionVipText = this.$enum.unionVip(item.unionVipType)
            }
          } else {
            this.$Message.error(res.data.msg)
          }
        }
      }).get()
     },
    selectOption(type) {
      if(!this.query.equal) this.query.equal = new Object()
      this.query.equal.unionVipType = type
      this.Init()
    },
     //搜索
    searchGet() {
      let sqlLike = {
        fields: ["user_name","union_mobile","user_id"],
        keyword: this.keywords,
      }
      this.query.sqlLike = sqlLike
      this.query.pageIndex = 1
      this.Init()
    },
    //重置
    reset() {
      delete this.query.sqlLike
      this.keywords = null
      this.Init()
    },
    vipStatusEnum(status) {
      switch(status) {
        case 0:
          return '待审核'
        case 1:
          return '通过'
        case 2:
          return '驳回'
      }
    },
    tagStyle(status) {
      switch(status) {
        case 0:
          return 'warning'
        case 1:
          return 'success'
        case 2:
          return 'orange'
        default:
          return 'default'
      }
    },
  },
  created(){
    this.Init()
  }
}
</script>
<style lang="less" scoped>
.imgs {
  width: 80%;
}
</style>